/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package br.uniceub.fsw.talentos.dao;

import br.uniceub.fsw.arquitetura.persistencia.dao.BaseDAO;
import br.uniceub.fsw.arquitetura.persistencia.dao.ConstrutorSQL;
import br.uniceub.fsw.talentos.dao.CargoDAO;
import br.uniceub.fsw.talentos.vo.CargoVO;
import br.uniceub.fsw.talentos.vo.SalarioVO;
import java.io.Serializable;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
import java.util.Set;

/**
 *
 * @author WinAdmin
 */
public class SalarioDAO extends BaseDAO<SalarioVO>{

    @Override
    public void inserir(SalarioVO salario) {

        ConstrutorSQL query = new ConstrutorSQL();

        query.append("INSERT INTO TB_SALARIO(CD_Cargo, VL_Salario, DT_InicioVigencia, DT_FimVigencia)");
		query.append("VALUES ( 1, ?, ?, ?)");

        List<?> parametros = criarParametros(

				salario.getVlSalario(),
                salario.getDtInicioVigencia(),
                salario.getDtFimVigencia()
				);

        executarInsercao(query.toString(), parametros);

        
        //    throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public void alterar(SalarioVO salario) {
    ConstrutorSQL query = new ConstrutorSQL();

        query.append(" UPDATE TB_Salario SET ");
        query.append(" VL_Salario = ?,");
        query.append(" DT_InicioVigencia = ?,");
        query.append(" DT_FimVigencia = ?");
        query.append(" WHERE ");
        query.append(" CD_Cargo = ?");

        List<?> parametros = criarParametros(
				salario.getVlSalario(),
                salario.getDtInicioVigencia(),
                salario.getDtFimVigencia(),
				salario.getCdCargo()
				);



        executarAlteracao(query.toString(), parametros);

        //    throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public void excluir(SalarioVO salario) {

        ConstrutorSQL query = new ConstrutorSQL();

        query.append("DELETE FROM TB_Salario");
        query.append("WHERE ID_SALARIO = ?");

        executarAlteracao(query.toString(), criarParametros(salario.getIdSalario()));

        //throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public SalarioVO consultarPorId(Serializable id) {
        SalarioVO salario = null;

        ConstrutorSQL query = new ConstrutorSQL();

        query.append("SELECT * FROM TB_Salario T WHERE T.ID_Salario = ?");

        salario = consultarUm(query.toString(), criarParametros(id));

        return salario;
        
        //    throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public List<SalarioVO> consultarPorExemplo(SalarioVO exemplo) {

        List<SalarioVO> listaRetorno = null;

        ConstrutorSQL query = new ConstrutorSQL();

        query.append("SELECT * FROM TB_Salario T WHERE 1=1");

        mapearQueryParaExemplo(query, exemplo);

        listaRetorno = consultar(query.toString(), recuperarParametros());

        return listaRetorno;
        //    throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    protected SalarioVO extrairObjetoResultado(ResultSet rs) throws SQLException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    protected void mapearQueryParaExemplo(ConstrutorSQL query, SalarioVO exemplo) {
        throw new UnsupportedOperationException("Not supported yet.");
    }


    public SalarioVO vincularSalarioAoCargo(CargoVO cargo, SalarioVO salario){

        ConstrutorSQL query = new ConstrutorSQL();
  //      CargoDAO c = new CargoDAO();
   //     CargoVO retorno = new CargoVO();


        query.append("SELECT * FROM TB_CARGO WHERE NO_CARGO LIKE '?' AND DS_ATIVIDADE LIKE '?'");
        consultar(query.toString());

        salario.setCdCargo(cargo.getIdCargo());

        this.inserir(salario);



        //throw new UnsupportedOperationException("Not supported yet.");


        return salario;
    }



}
